// pages/my/addCustomGoods/addCustomGoods.js
import * as appConfig from '../../../app-config.js'
var app = getApp()
Page({
  data: {
    versionNameId:'',
    verList:['']
  },
  onLoad: function(options) {
    this.setData({
      versionNameId:options.id
    })
  },
  bindVerControl(e){
    let index = e.currentTarget.dataset.index
    let verList = this.data.verList
      //添加删除自定义规格分类
      if (index==this.data.verList.length-1) {
        console.log('这是最后一个')
        verList.push('')
      }else{
        verList.splice(index,1)
      }
      this.setData({
        verList
      })
    },
  //获取input的内容
  bindEntryVer(e){
    console.log(e.detail.value)
    let index = e.currentTarget.dataset.jndex
    let ver = e.detail.value
    this.setData({
      ['verList['+index+']']:ver
    })
  },
  saveVer(){
    let verList = this.data.verList
    let values = ''
    verList.forEach(item=>{
      values+=item+','
    })
    let data = {
      versionNameId:this.data.versionNameId,
      values:values.substr(0,values.length-1)
    }
    console.log(data)
    app.request('wx_app/custom_merchandise/addVersionValue',data,'GET').then(res=>{
      console.log(res)
      if (res.code==1) {
        wx.showToast({
          title:'添加成功'
        })
        setTimeout(function(){
          wx.navigateBack({
            delta:1
          })
        },1500)
        
      }else{
        app.errorMsg(res.message)
      }
    })
  }
})

